//
//  HistoryCell.m
//  LabanBrowser
//
//  Created by -Xh- on 3/6/13.
//  Copyright (c) 2013 VNG. All rights reserved.
//

#import "HistoryCell.h"

@implementation HistoryCell

@synthesize delegate;
@synthesize currentHistory;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)setUpStyle{
    self.titleLabel.font=[UIFont boldSystemFontOfSize:17];
    self.urlLabel.font=[UIFont italicSystemFontOfSize:13];
    self.urlLabel.textColor=[UIColor grayColor];
    [self.starButton initialize];
    [self.starButton setImageOne:[UIImage imageNamed:@"star_off2.gif"] AndImageTwo:[UIImage imageNamed:@"star_on2.png"] ];
    self.starButton.delegate=self;
    
    self.starButton.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
    self.thumbnail.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    //self.titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    //self.urlLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGRect titleRect = CGRectMake(36, 10, self.contentView.frame.size.width - 83, 28);
    self.titleLabel.frame = titleRect;
    self.urlLabel.frame = CGRectMake(36, 32, self.contentView.frame.size.width - 83, 21);

}
#pragma mark TwoStateButtonDelegate
-(void)onTouchStateOne:(UIButton *)_button{
    [self.starButton swapState];
    if(self.delegate && [self.delegate respondsToSelector:@selector(saveBookmarkToDBWithHistory:)]){
        [self.delegate saveBookmarkToDBWithHistory:self.currentHistory];
    }
}
-(void)onTouchStateTwo:(UIButton *)_button{
    [self.starButton swapState];
    if(self.delegate && [self.delegate respondsToSelector:@selector(removeBookmarkFromDBWithHistory:)]){
        [self.delegate removeBookmarkFromDBWithHistory:self.currentHistory];
    }
}

@end
